package com.oscar.ehome.presenter;

import com.oscar.ehome.bean.loginbean.CodeBean;
import com.oscar.ehome.bean.loginbean.UserBean;
import com.oscar.ehome.bean.loginbean.idcardbean.IdBean;
import com.oscar.ehome.bean.loginbean.idcardbean.IdCardBean;
import com.oscar.ehome.bean.loginbean.idcardbean.MessageBean;
import com.oscar.ehome.bean.loginbean.logincompanyBean;
import com.oscar.ehome.bean.pagebean.DiaoChaInfo;
import com.oscar.ehome.bean.pagebean.StudyDetialBean;
import com.oscar.ehome.view.loginview.view.LoginView;
import com.oscar.ehome.model.HttpModel;
import com.oscar.ehome.model.HttpModelImple;
import com.oscar.ehome.model.OnHttpListener;
import com.oscar.ehome.view.pageview.view.DiaoChaView;
import com.oscar.ehome.view.pageview.view.StudyDetialView;

import java.io.File;
import java.util.Map;

/**
 * Created by oscar on 2017/6/21.
 */

public class LoginPresenter extends BasePresenter {

    HttpModel httpModel;
    LoginView loginView;
    DiaoChaView diaochaview;
    public LoginPresenter(LoginView loginView) {
        this.loginView = loginView;
        httpModel = new HttpModelImple();
    }
    public LoginPresenter(DiaoChaView diaochaview) {
        this.diaochaview = diaochaview;
        httpModel = new HttpModelImple();
    }
    public void getwenjianInfo(String token) {

        httpModel.getWenJianInfo(token,new OnHttpListener<StudyDetialBean>() {
            @Override
            public void onSuccess(StudyDetialBean obj) {

                if (loginView != null)
                    loginView.getbaojianjufile(obj);
            }

            @Override
            public void onError(String msg) {
                loginView.erry(msg);
            }

            @Override
            public void onFailure() {
            }
        });
    }
    public void getwelDiaochaInfo(String token) {

        httpModel.getDiaoChaInfo(token,new OnHttpListener<DiaoChaInfo>() {
            @Override
            public void onSuccess(DiaoChaInfo obj) {

                if (loginView != null)
                    loginView.getDiaocharesult(obj);
            }

            @Override
            public void onError(String msg) {
                loginView.erry(msg);
            }

            @Override
            public void onFailure() {
            }
        });
    }
    /**
     * 登录
     */
    public void logins(String phonenumber, String code, String deviceid, String deviceType, String clientId) {
        httpModel.login(phonenumber, code, deviceid, deviceType, clientId, new OnHttpListener<UserBean>() {
            @Override
            public void onSuccess(UserBean obj) {
                if (loginView != null)
                    loginView.navigateToHome(obj);
            }

            @Override
            public void onError(String msg) {
                if (loginView != null)
                    loginView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (loginView != null)
                    loginView.erroy();
            }
        });
    }

    /**
     * 请求验证码
     *
     * @param phonenumber
     */
    public void recvicecode(String phonenumber) {
        httpModel.recverCode(phonenumber, new OnHttpListener<logincompanyBean>() {
            @Override
            public void onSuccess(logincompanyBean obj) {
                if (loginView != null)
                    loginView.code(obj);
            }

            @Override
            public void onError(String msg) {
                if (loginView != null)
                    loginView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (loginView != null)
                    loginView.erroy();
            }
        });
    }

    /**
     * 客服电话
     */
    public void kefu() {
        httpModel.kefu(new OnHttpListener<CodeBean>() {
            @Override
            public void onSuccess(CodeBean obj) {
                if (loginView != null)
                    loginView.phoneNumber(obj);
            }

            @Override
            public void onError(String msg) {
                if (loginView != null)
                    loginView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (loginView != null)
                    loginView.erroy();
            }
        });
    }
}
